/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.panpf.sketch.sample.widget.page;

import me.panpf.sketch.SketchImageView;
import me.panpf.sketch.display.TransitionImageDisplayer;
import me.panpf.sketch.process.CircleImageProcessor;
import me.panpf.sketch.sample.AssetImage;
import me.panpf.sketch.sample.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.window.service.Display;
import ohos.agp.window.service.DisplayAttributes;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

import java.util.Optional;

/**
 * CircleImageProcessorTestPageView
 */
public class CircleImageProcessorTestPageView extends AbstractPageView {
    public CircleImageProcessorTestPageView(Context context, String name) {
        super(context, name);
    }

    @Override
    public void initView() {
        super.setRootView(loadView());

        SketchImageView sketchImageView = (SketchImageView) getRootView().findComponentById(ResourceTable.Id_image_circle);
        Optional<Display> display = DisplayManager.getInstance().getDefaultDisplay(super.getContext());
        DisplayAttributes displayAttributes = display.get().getAttributes();
        sketchImageView.getOptions().setMaxSize(displayAttributes.width / 2, displayAttributes.height / 2);
        sketchImageView.getOptions().setProcessor(CircleImageProcessor.getInstance());
        // sketchImageView.getOptions().setDisplayer(new TransitionImageDisplayer());
        sketchImageView.displayResourceImage(ResourceTable.Media_mei_nv);
    }

    private Component loadView() {
        ComponentContainer layout = (ComponentContainer) LayoutScatter.getInstance(super.getContext()).parse
                (ResourceTable.Layout_circle_page_view, null, false);

        return layout;
    }
}
